package Search;

public class Lower {

    private Lower(){}

    //查找比target小的最大数
    public static <E extends Comparable<E>> int lower(E[] arr,E target){
        int l = -1,r = arr.length - 1;
        while (l < r){
            int mid = l + (r - l + 1) / 2;//究极重点，二分法最难的就是循环不变量问题，这里不加1就会死循环
            if (arr[mid].compareTo(target) < 0)
                l = mid;
            else r = mid - 1;
        }
        return l;
    }
}
